﻿using System;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

using LTJ.Entity;
using LTJ.Common;
using LTJ.Config;
using LTJ.FrameWork;

namespace LTJ.WebPage.SystemManage.corp
{
    public partial class corpinfoedit : AdminPage
    {
        protected string opmode = SASRequest.GetString("opmode");
        protected int cid = SASRequest.GetInt("cid", 0);
        protected CompanyInfo cinfo = new CompanyInfo();

        protected void Page_Load(object sender, EventArgs e)
        {
            if (SASRequest.IsPost())
            {
                CorpEditOP();
            }
        }

        /// <summary>
        /// 企业新增操作
        /// </summary>
        protected void CorpEditOP()
        {
            if (CheckCookie())
            {
                string cname = SASRequest.GetString("cname");
                string ecname = SASRequest.GetString("ecname");
                string relater = SASRequest.GetString("relater");
                string relateform = SASRequest.GetString("relateform");
                string bio = SASRequest.GetString("bio");
                string mainstr = SASRequest.GetString("mainstr");
                string phone = SASRequest.GetString("phone");
                string email = SASRequest.GetString("email");
                string weburl = SASRequest.GetString("weburl");
                string msn = SASRequest.GetString("msn");
                int mcount = SASRequest.GetInt("managercount", -1);
                int ucount = SASRequest.GetInt("usercount", -1);
                int corp_score = SASRequest.GetInt("corp_score", 0);

                cinfo.cname = cname;
                cinfo.ecname = ecname;
                cinfo.relater = relater;
                cinfo.relateform = Utils.RemoveHtml(Utils.ChkSQL(relateform));
                cinfo.bio = Utils.RemoveHtml(Utils.ChkSQL(bio));
                cinfo.Mains = mainstr;
                cinfo.Phone = Utils.ChkSQL(phone);
                cinfo.Email = Utils.ChkSQL(email);
                cinfo.MSN = Utils.ChkSQL(msn);
                cinfo.mcount = mcount;
                cinfo.ucount = ucount;
                cinfo.Scores = corp_score;

                if (opmode == "edit")
                {
                    string logourl = FrameWorkUtil.SaveCorpLogo(cinfo.id);
                    if (logourl != "") cinfo.logo = logourl;
                    Companys.UpdateCompany(cinfo);
                }
                else if (opmode == "add")
                {
                    cinfo.status = 1;
                    int newcid = Companys.CreateCompany(cinfo);

                    if (newcid <= 0)
                    {
                        base.RegisterStartupScript("PAGETEMPLATE", "企业编辑失败，请与管理员联系！");
                    }

                    if (FrameWorkUtil.IsPostFile())
                    {
                        CompanyInfo newcinfo = Companys.GetCompanyByID(newcid);
                        newcinfo.logo = FrameWorkUtil.SaveCorpLogo(newcinfo.id);
                        Companys.UpdateCompany(newcinfo);
                    }
                }

                base.RegisterStartupScript("PAGE", "parent.document.getElementById('reclick').click();parent.Lightview.hide();");
            }
        }

        #region Web 窗体设计器生成的代码

        override protected void OnInit(EventArgs e)
        {
            InitializeComponent();
            base.OnInit(e);
        }

        private void InitializeComponent()
        {
            if (opmode == "edit")
            {
                cinfo = Companys.GetCompanyByID(SASRequest.GetInt("cid", 0));
            }
        }

        #endregion
    }
}